package com.ayoka.parenting.ui.grown.detail;

import com.ayoka.parenting.Constants;
import com.ayoka.parenting.bean.BaseResponse;
import com.ayoka.parenting.bean.BasicUserInfoBean;
import com.ayoka.parenting.bean.ClassroomBean;
import com.ayoka.parenting.bean.ClassroomDetailBean;
import com.ayoka.parenting.http.API;
import com.ayoka.parenting.http.HttpBeanInterceptCallback;
import com.ayoka.parenting.interf.CallbackUtil;
import com.ayoka.parenting.interf.RequestCallback;
import com.ayoka.parenting.mvp.BasePresenter;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: MVPPlugin.
 * @ClassName: GrownDetailModel&.
 * @Description: .
 * @Author: jincp.
 * @CreateDate: 2019/10/10 18:17.
 */
public class GrownDetailModel implements GrownDetailContract.Model{


    @Override
    public void getClassroomDetailData(final BasePresenter presenter, final String classroomId, final RequestCallback<ClassroomDetailBean> callback) {
        API.getClassroomDetailData(presenter, classroomId, new HttpBeanInterceptCallback<BaseResponse<ClassroomDetailBean>>() {
            @Override
            public void onSuccess(BaseResponse<ClassroomDetailBean> response) {
                CallbackUtil.notifySuccess(callback, response.data);
            }

            @Override
            public void onFailure(int errorCode, String errorMessage) {
                if (errorCode == Constants.WX_ERROR_TOKEN) {
                    getClassroomDetailData(presenter, classroomId, callback);
                    return;
                }
                CallbackUtil.notifyFailure(callback, errorCode, errorMessage);
            }
        });
    }

    @Override
    public List<BasicUserInfoBean> getCoachListData() {
        List<BasicUserInfoBean> result = new ArrayList<>();
        result.add(new BasicUserInfoBean("", "克里斯多福·孟", "https://cdn.ayoka.cn/upload/focusgroup/img/image_coach_moon.png"));
        result.add(new BasicUserInfoBean("", "雷内·费布拉罗", "https://cdn.ayoka.cn/upload/focusgroup/img/image_coach_rany.png"));
        result.add(new BasicUserInfoBean("", "马莉", "https://cdn.ayoka.cn/upload/focusgroup/img/image_coach_mary.png"));
        result.add(new BasicUserInfoBean("", "蒋竹怡", "https://cdn.ayoka.cn/upload/focusgroup/img/image_coach_abby.png"));
        result.add(new BasicUserInfoBean("", "肖梦娜", "https://cdn.ayoka.cn/upload/focusgroup/img/image_coach_mengna.png"));
        result.add(new BasicUserInfoBean("", "闾婧", "https://cdn.ayoka.cn/upload/focusgroup/img/image_coach_lvjing.png"));
        return result;
    }

    @Override
    public void joinClassroom(final BasePresenter presenter, final String classroomId, final RequestCallback<BaseResponse> callback) {
        API.joinClassroom(presenter, classroomId, new HttpBeanInterceptCallback<BaseResponse>() {
            @Override
            public void onSuccess(BaseResponse response) {
                CallbackUtil.notifySuccess(callback, response);
            }

            @Override
            public void onFailure(int errorCode, String errorMessage) {
                if (errorCode == Constants.WX_ERROR_TOKEN) {
                    joinClassroom(presenter, classroomId, callback);
                    return;
                }
                CallbackUtil.notifyFailure(callback, errorCode, errorMessage);
            }
        });
    }
}
